package com.pubinfo.passbook.engine.process.variable.medicine;

import com.pubinfo.passbook.common.model.dto.witeoff.MedicineOnJobOrRetireDTO;
import com.pubinfo.passbook.common.model.ruler.PayInformation;
import lombok.extern.slf4j.Slf4j;

import java.math.BigDecimal;
import java.util.List;

/**
 * @author zhouch
 * @date 2022/3/9 10:14
 */
@Slf4j
public class BurdenSelfAmountProcessor extends MedicineVariableProcessor {
    
    @Override
    public BigDecimal get(MedicineOnJobOrRetireDTO data) {

        log.info("执行参数处理器: {}", this.getClass().getSimpleName());

        List<PayInformation> payInformations = cache.getPayInformationData();

        BigDecimal selfpaymentAmounts = new BigDecimal(0);

        for (PayInformation payInformation : payInformations) {
            //个人现金支付
            BigDecimal sumAmountSelf = payInformation.getSelfpaymentCost();
            if (sumAmountSelf.equals(new BigDecimal(-0.0000999))) {
                cache.markNeedAudit();
                log.info("{} ==> 需要人工审核.", getClass().getSimpleName());
                sumAmountSelf = BigDecimal.ZERO;
            }
            //个人现金支付
            BigDecimal ownPayAmount = payInformation.getOwnPayAmount();
            if (ownPayAmount.equals(new BigDecimal(-0.0000999))) {
                cache.markNeedAudit();
                log.info("{} ==> 需要人工审核.", getClass().getSimpleName());
                ownPayAmount = BigDecimal.ZERO;
            }
            //个人自理
            BigDecimal selfpaymentCare = payInformation.getSelfpaymentCare();
            if (selfpaymentCare.equals(new BigDecimal(-0.0000999))) {
                cache.markNeedAudit();
                log.info("{} ==> 需要人工审核.", getClass().getSimpleName());
                selfpaymentCare = BigDecimal.ZERO;
            }

            //自负=个人现金支付-自费-自理
            selfpaymentAmounts = selfpaymentAmounts.add(ownPayAmount.subtract(sumAmountSelf).subtract(selfpaymentCare));
        }

        log.info("参数处理器: {} 结果: {}", this.getClass().getSimpleName(), selfpaymentAmounts);

        return selfpaymentAmounts;
    }
}
